// import { module } from "./module/index";
import VueRouter from 'vue-router'
import Vue from 'vue'
import Layout from '@/components/Layout/index.vue'

// 使用VueRouter
Vue.use(VueRouter)
// 读取module文件里面所有的路由
// const modulesFiles = import.meta.glob('./module/**.js', { eager: true })
export let routes = [
    {
        path: '/',
        name: '/',
        redirect: '/carNumber',
        component: Layout,
        children: [
            {
                path: 'carNumber',
                name: 'carNumber',
                icon: 'carNumber.png',
                component: () => import('@/views/CarNumber.vue'),
                meta: {
                    title: '车牌号码识别',
                },
            },
            {
                path: 'laneDetect',
                name: 'laneDetect',
                icon: 'laneDetect.png',
                component: () => import('@/views/LaneDetect.vue'),
                meta: {
                    title: '车道线检测',
                },
            },
            {
                path: 'parkingSpace',
                name: 'parkingSpace',
                icon: 'parkingSpace.png',
                component: () => import('@/views/ParkingSpace.vue'),
                meta: {
                    title: '停车场车位识别',
                },
            },
            {
                path: 'fatigue',
                name: 'fatigue',
                icon: 'fatigue.png',
                component: () => import('@/views/Fatigue.vue'),
                meta: {
                    title: '疲劳检测',
                },
            },
            {
                path: 'carTrack',
                name: 'carTrack',
                icon: 'carTrack.png',
                component: () => import('@/views/CarTrack.vue'),
                meta: {
                    title: '车辆追踪车流量统计',
                },
            },
        ],
    },
]
// 把js里面的路由添加到routes上
// for (const key of Object.keys(modulesFiles)) {
//     routes.push(...modulesFiles[key].default)
// }

const router = new VueRouter({
    mode: 'history',
    base: '/',
    routes,
})

// 重复点击导航时，控制台出现报错
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch((err) => err)
}

// router.beforeEach((to, from, next) => {
//   if (to.path == '/login') {
//     next()
//   } else {
//     if (getToken()) {
//       next()
//     } else {
//       next('/login')
//     }
//   }
// })

export default router
